//
//  YBBLE.h
//  YBBLE
//
//  Created by LPC on 2018/2/5.
//  Copyright © 2018年 audi. All rights reserved.
//
#define BLE [YBBLE ble]
#import <CoreBluetooth/CoreBluetooth.h>
#import <ReactiveObjC/ReactiveObjC.h>

@class YBBLE;
@protocol YBBLEDelegate<NSObject>
@optional

/**
 找到蓝牙回调
 @param ble ble
 @param advertisementData 广播信息
 */
- (void)yb_BLE:(YBBLE*)ble didFindBLEAdvertisementData:(NSDictionary<NSString *,id> *)advertisementData RSSI:(NSNumber *)RSSI;

/**
 收到车锁返回的信息

 @param ble ble
 @param firstValue 返回报文1
 @param secondValue 返回报文2
 */
- (void)yb_BLE:(YBBLE*)ble didUpdataFirstValue:(NSString *)firstValue secondValue:(NSString *)secondValue isEnd:(BOOL)isEnd;

/**
 *  蓝牙状态更新
 */
- (void)yb_BLE:(YBBLE *)ble didUpdateCentralManagerState:(CBCentralManagerState)state;

/**
 *  进入某项频道失败
 */
- (void)yb_BLEdidFailStart:(YBBLE *)ble ;

/**
 *  任务超时
 */
- (void)yb_BLETaskTimerOut:(YBBLE *)ble;

@end
#import <Foundation/Foundation.h>
#import "YBBLEAdvertisementData.h"
@interface YBBLE : NSObject

typedef NS_ENUM(NSInteger,YBBLEChannel){//频道
    YBBLEChannel_openBLELock = 0,//开锁
    YBBLEChannel_search,
    YBBLEChannel_listen,
    YBBLEChannel_searchStaion,
    YBBLEChannel_commom//返回所有的
};

typedef NS_ENUM(NSInteger,YBErrorCode){
    YBBLEDelegate_timeOut = 0//超时
};

///当前频道 定义的频道内部会有逻辑，如果 需要新的频道，请区分上面已经定义的频道（主频道）
@property (nonatomic ,assign)YBBLEChannel channel;
@property (nonatomic ,assign)CBCentralManagerState state;
//用来区分频道(子频道)
@property (nonatomic ,copy)NSString *useChannel;
@property (nonatomic ,weak)id<YBBLEDelegate>delegate;

@property (nonatomic ,strong ,readonly)NSString *returnMsgFirst;
@property (nonatomic ,strong ,readonly)NSString *returnMsgSecond;

///构造方法
+ (instancetype)ble;

/**
 开锁
 @param lockName 开锁名称
 @param openLockMsg 开锁报文
 @param timeOutValue 超时时间
 @discuss channel YBBLEChannel_openBLELock 这个超时是链接锁超时
 */
- (void)yb_openBLELock:(NSString *)lockName
            UseChannel:(NSString *)UseChannel
           openLockMsg:(NSString *)openLockMsg
          timeOutValue:(NSTimeInterval)timeOutValue
              delegate:(id<YBBLEDelegate>)delegate;

/**
 找锁
 @params timeOutIntervel 找寻超时时间
 @discuss channel YBBLEChannel_commom
 @discuss - (void)yb_BLE:(YBBLE*)ble didFindBLEAdvertisementData:(NSDictionary<NSString *,id> *)advertisementData;
 @discuss 这个函数在回调完成代理后会自动结束扫描
 */
- (void)yb_searchBLELock:(NSString *)lockName UseChannel:(NSString *)useChannel timeOutIntervel:(NSTimeInterval)timeOutIntervel delegate:(id<YBBLEDelegate>)delegate;

/**
 查找永安站
 @param timeOutIntervel 超时时长
 @param type 0.永安站 1.锁车器 2.永安站+锁车器  default 永安站+锁车器；
 */
- (void)yb_searchStationUseChannel:(NSString *)useChannel type:(int)type TimeOutIntervel:(NSTimeInterval)timeOutIntervel delegate:(id<YBBLEDelegate>)delegate;

/**
 监听锁状态
 @param lockName 车锁号
 @discuss channel YBBLEChannel_listen
 @discuss - (void)yb_BLE:(YBBLE*)ble didFindBLEAdvertisementData:(NSDictionary<NSString *,id> *)advertisementData;
 @discuss 监听到代理后不会自动停止扫描需要调用 stopScan来停止扫描
 */

- (void)yb_listeningBLELock:(NSString *)lockName delegate:(id<YBBLEDelegate>)delegate;

/**
 搜索附近所有设备
*/
- (void)yb_listeningBLELockAllDelegate:(id<YBBLEDelegate>)delegate;

/**
 *  停止扫描
 */
- (void)stopScan;

/**
 *  清除内置定时器
 */
- (void)cleanTimer;

/**
 *  重置蓝牙
 */
- (void)clean;


#pragma ....
- (YBBLE *(^)(YBBLEChannel))YBchannel;

@end
